﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace SvgViewer.Entities
{
    /// <summary>
    /// 背景模板选择器
    /// </summary>
    public class BackgroundItemDataTemplateSelector : DataTemplateSelector
    {
        /// <summary>
        /// 根据内容选择背景显示模板
        /// </summary>
        /// <param name="item">item</param>
        /// <param name="container">内容</param>
        /// <returns>返回匹配的模板</returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var element = (FrameworkElement)container;
            if (item is Geometry g && g.Bounds != Rect.Empty)
            {
                return element.FindResource("BackgroundItemTemplate") as DataTemplate;
            }

            return element.FindResource("NullBackgroundItemTemplate") as DataTemplate;
        }
    }
}